package com.hualan.sfzy.service.course.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.entity.CourseClassification;
import com.hualan.sfzy.mapper.course.CourseClassificationMapper;
import com.hualan.sfzy.service.course.CourseClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CourseClassificationServiceImpl implements CourseClassificationService {
    @Autowired
    private CourseClassificationMapper courseClassificationMapper;
    @Override
    public int add(CourseClassification entity) {
        return courseClassificationMapper.insert(entity);
    }

    @Override
    public int edit(CourseClassification entity) {
        return courseClassificationMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return courseClassificationMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseClassificationMapper.deleteBatch(ids);
    }

    @Override
    public List<CourseClassification> find() {
        return courseClassificationMapper.selectAll();
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CourseClassification entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseClassification> courseClassifications = courseClassificationMapper.select(entity);
        PageInfo<CourseClassification> pageInfo = new PageInfo<>(courseClassifications);
        Map<String, Object> result = new HashMap<>();
        result.put("list", pageInfo.getList());
        result.put("total", pageInfo.getTotal());
        result.put("pageNum", pageInfo.getPageNum());
        result.put("pageSize", pageInfo.getPageSize());
        result.put("pages", pageInfo.getPages());
        return result;
    }

    @Override
    public CourseClassification findById(Integer id) {
        return courseClassificationMapper.selectById(id);
    }
}
